package com.crazy.crazytransactionservice.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.crazy.crazymodel.model.entity.Position;
import com.crazy.crazymodel.model.vo.BankCardAndShare;
import com.crazy.crazytransactionservice.model.ProductAndShare;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface PositionMapper extends BaseMapper<Position> {
    @Select("select productID , sum(share)as TotalShare,SUM(IFNULL(freezeShare, 0)) as TotalFreezeShare from position where customerID=#{customerID} group by productId")
    IPage<ProductAndShare> getProductAndShare(IPage<?> page, @Param("customerID") int customerID);

    @Select("select bankCardNumber,(share - COALESCE(freezeShare, 0)) AS validShare from position where customerID=#{customerID} and productId=#{productID}")
    public List<BankCardAndShare> getBankCardAndShare(@Param("customerID")int customerID, @Param("productID")int productID);
}
